<?php
class State extends Controller {
	function State() {
		parent::Controller();
	}

	function showAll() {
		$this->load->model('state_model');
		$data['title'] = 'Frool';
		$data['states'] = $this->state_model->readAll();
		$theme = $this->config->item('active_theme');
		$data['content'] = $this->load->view($theme.'state/showAll', $data, true);
		$this->load->view($theme.'layout', $data);
	}

	function add() {
		$this->load->model('state_model');
		if ($this->input->post('Submit')) {
			$this->state_model->create();
			redirect('state/showAll');
		}
		$data['title'] = 'Frool';
		$theme = $this->config->item('active_theme');
		$data['content'] = $this->load->view($theme.'state/add', $data, true);
		$this->load->view($theme.'layout', $data);
	}

	function edit($id) {
		$this->load->model('state_model');
		if ($this->input->post('Submit')) {
			$this->state_model->update($id);
			redirect('state/showAll');
		}
		$data['title'] = 'Frool';
		$data['state'] = $this->state_model->read($id);
		$theme = $this->config->item('active_theme');
		$data['content'] = $this->load->view($theme.'state/edit', $data, true);
		$this->load->view($theme.'layout', $data);
	}
}
?>
